<template>
  <List ref="list" class="whole" component-name="NavFilter" :finished.sync="finished" :reset-fun="resetData" :load="load" :refresh="load">
    <ShowWindow v-for="(l,i) in list" :key="i" :line-clamp="2" :show="false" :host="ADS_STATIC_PATH" :src="l.coverOriginalImageUrl || l.coverImageUrl" :show-price="false" :name="l.exhibitionName" @click.native.stop="clickHandle(l)" />
  </List>
</template>
<script>
import List from '@/components/List'
import ShowWindow from '@/components/ShowWindow'
import { getSchemeSearchPage, getRoomScreen } from '@/apis/scheme2.0'
import { mapGetters, mapMutations, mapActions } from 'vuex'
export default {
  name: 'SearchSchemeNew',
  components: {
    List,
    ShowWindow
  },
  refresh: true,
  props: {
    searchValue: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      list: [],
      finished: false,
      ADS_STATIC_PATH: `${process.env.VUE_APP_ADS_STATIC}`
    }
  },
  computed: {
    ...mapGetters('nav', ['filterData'])
  },
  watch: {
  },
  activated() {
    // this.getFilterData(getRoomScreen)
  },
  created() {
    this.$on('refresh', this.resetPageData)
  },
  methods: {
    ...mapActions('nav', ['getFilterData']),
    ...mapMutations('nav', ['updateFilterData']),
    resetPageData() {
      if (this.$refs.list) {
        this.$refs.list.resetPageData()
      }
    },
    load(page, pageSize) {
      const filtersRaw = [
        { id: 'status0', property: 'status', operator: '=', value: 1 },
        { id: 'programmeTypeCode0', property: 'programmeTypeCode', operator: '<>', value: 'REAL_ROOM' }
      ]
      if (this.searchValue) {
        filtersRaw.push({ id: 'programmeName0', property: 'programmeName', operator: 'LIKE', value: this.searchValue })
      }
      /* const data = {
        page,
        rows: pageSize,
        isLenovoSearch: 0,
        sort: 0, // 排序规则 0、综合 1、时间排序 2、最多点赞数 3、最多浏览数
        keyWord: this.searchValue
      } */
      const data = {
        page,
        rows: pageSize,
        sort: '',
        order: 'DESC',
        pageFlag: true,
        onlyCountFlag: false,
        filtersRaw: JSON.stringify(filtersRaw),
        sortersRaw: JSON.stringify([]),
        paramsRaw: JSON.stringify({})
      }

      return getSchemeSearchPage(data).then(res => {
        this.list.push(...(res.data.records || []))
        if (this.list.length >= res.data.total) {
          this.finished = true
        }
      })
    },
    resetData() {
      this.list = []
    },
    clickHandle(item) {
      this.$router.push({ name: 'SchemeDetail', params: { id: item.id }})
    }
  }
}
</script>
<style lang="less">
.whole{
}
</style>
